<?php
/**
 * blank sidebox - allows a blank sidebox to be added to your site
 *
 * @package templateSystem
 * @copyright 2007 Kuroi Web Design
 * @copyright Portions Copyright 2003-2007 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_static_news_sidebox.php 2 2008-10-18 02:36:34Z numinix $
 */

  include_once(DIR_FS_CATALOG.DIR_WS_FUNCTIONS.'/extra_functions/php_cache.php');
  $cache_file = DIR_FS_SQL_CACHE . '/rss_forum_header.cache';
  @define(NUMINIX_RSS_PARSER, 'magpierss');
  //$cache = true;
  $content = '';
//   $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
  $content .= '<h3><a href="#">Community Forum.</a></h3><div>' . TEXT_RSS_FORUM_HEADER . '<br />';
  // check if a cache file exists and if not, create the content for one
  if ( (!file_exists($cache_file)) || (file_exists($cache_file) && ((time() - filemtime($cache_file)) >= ADMIN_RSS_HEADER_CACHE)) ) { // create new cache file
    //$cache = false;

    switch(NUMINIX_RSS_PARSER) {
    case 'magpierss':
      require_once(DIR_FS_CATALOG.DIR_WS_CLASSES . 'rss/magpierss/rss_fetch.inc');
      $rss = fetch_rss(ADMIN_RSS_HEADER_RSS_FEED);

      $items_array = array();
      $items_array = array_slice($rss->items, 0, (int)ADMIN_RSS_HEADER_MAX);
      foreach($items_array as $item) {
          $content_for_cache .= '<li><a target="_blank" href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item['link'])) . '">' . $item['title'] . '</a></li>';
      }
      break;
    case 'patrss':
      require(DIR_FS_CATALOG.DIR_WS_CLASSES . "rss/patRSS.php");
      $patRss = new patRSS(ADMIN_RSS_HEADER_RSS_FEED);
      $items_array = array();
      $items_array = $patRss->getItems(4);
      foreach($items_array as $item) {
          $content_for_cache .= '<li><a target="_blank" href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item['link'])) . '">' . $item['title'] . '</a></li>';
      }
      break;
    case 'simplepie':
      require_once(DIR_FS_CATALOG.DIR_WS_CLASSES . 'rss/simplepie/simplepie.inc');
      $rss = new SimplePie(ADMIN_RSS_HEADER_RSS_FEED);
      $rss->handle_content_type();
      foreach ($rss->get_items() as $item) {
          $content_for_cache .= '<li><a target="_blank" href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item->get_permalink())) . '">' . $item->get_title() . '</a></li>';
      }
      break;
    }
    $content_for_cache = '<ul>';
    foreach($items_array as $item) {
        $content_for_cache .= '<li><a target="_blank" href="' . $item['link'] . '">' . $item['title'] . '</a></li>';
    }
//     $content_for_cache .= '</ul>';
    $content .= setCache($cache_file, $content_for_cache);
  } else {
    // get file contents
    $content .= getCache($cache_file);
  }
  $content .= '</ul>';

echo $content;